# -*- coding:UTF-8 -*-

import configparser
import hashlib
from os import path
from xiao.directory import *

global url, key, taobaoUserId, token, encryptType, encryptParam
url = 'http://tmallreader.sqreader.com/tbapi/publish/meta'
hl = hashlib.md5()
hl.update(url.encode(encoding = 'utf-8'))
key = hl.hexdigest()
taobaoUserId = ''
token = ''
encryptType = '-1'
encryptParam = 'data'

'''
配置读取类
# @author bricker
'''
class Settings(object):

    def __init__(self):
        global url, key, taobaoUserId, token, encryptType, encryptParam
        configPath = Directory.getConfig()
        print('加载配置文件:%s'%configPath)
        if not path.exists(configPath):
            return
        conf = configparser.ConfigParser()
        conf.read(configPath)
        url = conf.get('conf', 'url')
        key = conf.get('conf', 'key')
        taobaoUserId = conf.get('conf', 'taobaoUserId')
        token = conf.get('conf', 'token')
        encryptType = conf.get('conf', 'encryptType')
        encryptParam = conf.get('conf', 'encryptParam')

    @staticmethod
    def getUrl():
        global url
        return url

    @staticmethod
    def getKey():
        global key
        return key

    @staticmethod
    def getTaobaoUserId():
        global taobaoUserId
        return taobaoUserId

    @staticmethod
    def getToken():
        global token
        return token

    @staticmethod
    def getEncryptType():
        global encryptType
        return encryptType

    @staticmethod
    def getEncryptParam():
        global encryptParam
        return encryptParam

settings = Settings()